<?php

namespace app\admin\controller;
use think\Config;
use think\Controller;
use think\Db;
//会员员模块
class User extends Allow{
	//会员列表
	public function getIndex(){
		
		$request=request();
		$k = $request->param("k");//获取搜索值 k
		
		$data = Db::table("h_user")->where("loginname","like","%".$k."%")->paginate(2);
		return $this->fetch("user/index",["data"=>$data,"k"=>$k,"data2"=>$request->param()]);//引入列表模版
	}
	//执行删除
	public function getDelete(){
		$request = request();
		$id = $request->param("id");

		$res = Db::table("h_user")->delete($id);
		if($res){
				$this->success("ok","/adminuser/index");
			}else{
				$this->error("on","/adminuser/index");
			}
	}

	//激活或禁用
	public function getStatus(){
		$request=request();
		$status = Db::table("h_user")->where("id",$request->param("id"))->value("status");
		if($status =='1'){
			$res = Db::table("h_user")->where('id',$request->param("id"))->update(['status'=>'0']);
			if($res){
				$this->success("ok","/adminuser/index");
			}else{
				$this->error("on","/adminuser/index");
			}
		}else{
			$res = Db::table("h_user")->where('id',$request->param("id"))->update(['status'=>'1']);
			if($res){
				$this->success("ok","/adminuser/index");
			}else{
				$this->error("on","/adminuser/index");
			}
		}
	}
}
